package com.example.drive.bean

import android.os.Parcelable
import android.os.Parcel
import android.os.Parcelable.Creator
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey

const val ResultBean_tableName = "ResultBean"

@Entity(tableName = ResultBean_tableName)
class ResultBean() : Parcelable {
    @PrimaryKey(autoGenerate = true)
    @ColumnInfo(name = "id", typeAffinity = ColumnInfo.INTEGER)
    var id: Int? = null // 数据库要求是Int类型,json请求的是String类型

    @ColumnInfo(name = "question", typeAffinity = ColumnInfo.TEXT)
    var question: String? = null

    @ColumnInfo(name = "answer", typeAffinity = ColumnInfo.TEXT)
    var answer: String? = null

    @ColumnInfo(name = "item1", typeAffinity = ColumnInfo.TEXT)
    var item1: String? = null

    @ColumnInfo(name = "item2", typeAffinity = ColumnInfo.TEXT)
    var item2: String? = null

    @ColumnInfo(name = "item3", typeAffinity = ColumnInfo.TEXT)
    var item3: String? = null

    @ColumnInfo(name = "item4", typeAffinity = ColumnInfo.TEXT)
    var item4: String? = null

    @ColumnInfo(name = "explains", typeAffinity = ColumnInfo.TEXT)
    var explains: String? = null

    @ColumnInfo(name = "url", typeAffinity = ColumnInfo.TEXT)
    var url: String? = null

    @ColumnInfo(name = "file", typeAffinity = ColumnInfo.BLOB)
    var file: ByteArray? = null

    constructor(parcel: Parcel) : this() {
        id = parcel.readValue(Int::class.java.classLoader) as? Int
        question = parcel.readString()
        answer = parcel.readString()
        item1 = parcel.readString()
        item2 = parcel.readString()
        item3 = parcel.readString()
        item4 = parcel.readString()
        explains = parcel.readString()
        url = parcel.readString()
        file = parcel.createByteArray()
    }

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeValue(id)
        parcel.writeString(question)
        parcel.writeString(answer)
        parcel.writeString(item1)
        parcel.writeString(item2)
        parcel.writeString(item3)
        parcel.writeString(item4)
        parcel.writeString(explains)
        parcel.writeString(url)
        parcel.writeByteArray(file)
    }

    override fun describeContents(): Int {
        return 0
    }

    companion object CREATOR : Creator<ResultBean> {
        override fun createFromParcel(parcel: Parcel): ResultBean {
            return ResultBean(parcel)
        }

        override fun newArray(size: Int): Array<ResultBean?> {
            return arrayOfNulls(size)
        }
    }

}